package traductor;


/**
 *
 * @author bruno
 */
public class Tela extends javax.swing.JFrame {
    TranslatorEngine engine= new TranslatorEngine();
    boolean firstRun=true;
    public Tela() {
        initComponents();
    }

    private void translateAndUpdateScreen() {    	
        if (firstRun) {
            sourceArea.setText("Copy any text and click in this window");
            firstRun = false;
        }else{
        sourceArea.setText(engine.getSourceText());
        translatedText.setText(engine.translateText());	
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        labelSorceArea1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        sourceArea = new javax.swing.JTextArea();
        labelSorceArea = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        translatedText = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("J [help in reading]");
        setBackground(new java.awt.Color(255, 255, 255));
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });
        addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                formFocusGained(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jPanel1FocusGained(evt);
            }
        });

        labelSorceArea1.setBackground(new java.awt.Color(0, 204, 0));
        labelSorceArea1.setFont(new java.awt.Font("Arial", 0, 14));
        labelSorceArea1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labelSorceArea1.setText("Texto Original");
        labelSorceArea1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        labelSorceArea1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                labelSorceArea1FocusGained(evt);
            }
        });

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        sourceArea.setColumns(20);
        sourceArea.setEditable(false);
        sourceArea.setFont(new java.awt.Font("Arial", 0, 14));
        sourceArea.setLineWrap(true);
        sourceArea.setRows(5);
        sourceArea.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                sourceAreaMouseClicked(evt);
            }
        });
        sourceArea.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                sourceAreaFocusGained(evt);
            }
        });
        jScrollPane1.setViewportView(sourceArea);

        labelSorceArea.setBackground(new java.awt.Color(0, 204, 0));
        labelSorceArea.setFont(new java.awt.Font("Arial", 0, 14));
        labelSorceArea.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labelSorceArea.setText("Texto Traduzido");
        labelSorceArea.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        labelSorceArea.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                labelSorceAreaFocusGained(evt);
            }
        });

        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        translatedText.setColumns(20);
        translatedText.setEditable(false);
        translatedText.setFont(new java.awt.Font("Arial", 0, 14));
        translatedText.setLineWrap(true);
        translatedText.setRows(5);
        translatedText.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                translatedTextFocusGained(evt);
            }
        });
        jScrollPane2.setViewportView(translatedText);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelSorceArea, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE)
                    .addComponent(labelSorceArea1, javax.swing.GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelSorceArea1, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(labelSorceArea, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_formFocusGained
        translateAndUpdateScreen();
    }//GEN-LAST:event_formFocusGained

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed

    }//GEN-LAST:event_formWindowClosed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        engine.start();
    }//GEN-LAST:event_formWindowOpened

    private void translatedTextFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_translatedTextFocusGained
        translateAndUpdateScreen();
    }//GEN-LAST:event_translatedTextFocusGained

    private void sourceAreaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_sourceAreaFocusGained
        translateAndUpdateScreen();
    }//GEN-LAST:event_sourceAreaFocusGained

    private void labelSorceAreaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_labelSorceAreaFocusGained
        translateAndUpdateScreen();
    }//GEN-LAST:event_labelSorceAreaFocusGained

    private void labelSorceArea1FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_labelSorceArea1FocusGained
        translateAndUpdateScreen();
    }//GEN-LAST:event_labelSorceArea1FocusGained

    private void jPanel1FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jPanel1FocusGained
        translateAndUpdateScreen();
    }//GEN-LAST:event_jPanel1FocusGained

    private void sourceAreaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sourceAreaMouseClicked
       
    }//GEN-LAST:event_sourceAreaMouseClicked

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
       engine.stop();
    }//GEN-LAST:event_formWindowClosing

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        new Tela().setVisible(true);

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel labelSorceArea;
    private javax.swing.JLabel labelSorceArea1;
    private javax.swing.JTextArea sourceArea;
    private javax.swing.JTextArea translatedText;
    // End of variables declaration//GEN-END:variables
}